package com.selune.online.ordering.system.common.util;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.concurrent.ThreadLocalRandom;

/**
 * Id 生成工具
 *
 * @author xiaoyp
 * @date 2020/2/28
 */

public class IdUtils {
	
	public static Long orderGenId() {
		ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
		long random = threadLocalRandom.nextLong(111111, 999999);
		LocalDate localDate = LocalDate.now();
		String date = String.valueOf(localDate).replaceAll("-", "");
		return Long.valueOf("11" + date + random);
	}
	
	public static Long goodsGenId() {
		ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
		long random = threadLocalRandom.nextLong(1111, 9999);
		LocalDate localDate = LocalDate.now();
		String date = String.valueOf(localDate).replaceAll("-", "").substring(4);
		return Long.valueOf("22" + date + random);
	}
	
	public static Long userGenId() {
		ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
		long random = threadLocalRandom.nextLong(111, 999);
		int day = LocalDate.now().getDayOfMonth();
		return day < 10 ? Long.valueOf("33" + "0" + day + random) : Long.valueOf("33" + day + random);
	}
	
	public static void main(String[] args) {
		System.out.println(orderGenId());
		System.out.println(goodsGenId());
		System.out.println(userGenId());
		System.out.println(LocalDateTime.now());
	}
}
